package com.pms.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pms.entity.Message;
import com.pms.entity.Users;
import com.pms.service.MessageService;
import com.pms.util.GetSession;
import com.pms.util.TimeDateUtil;


/**
 * @author handy
 * 2013-03-13
 */
public class ToMessage extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String message = request.getParameter("message");
		Users user = (Users)GetSession.getSession(request).getAttribute("user");
		
		//System.out.println(user.getUser_name());
		//System.out.println(user.getUser_id());
		
		Message mes = new Message();
		mes.setMescontent(message);
		mes.setUserid(user.getUser_id());
		mes.setUsername(user.getUser_name());
		mes.setCreatetime(TimeDateUtil.getNow());

		MessageService mesService = new MessageService();
		mesService.save(mes);
		response.sendRedirect("toProject.jspx");
		
		
		//request.getRequestDispatcher("/WEB-INF/project.jsp").forward(request, response);
	}

}
